package org.study.tk.boot.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.study.tk.boot.model.Student;
import org.study.tk.boot.service.StudentService;

import java.util.List;

/**
 * 该类的描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2021-04-20
 */
@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    @PostMapping(value = "/insert")
    public int insertSelective(Student student) {
        return studentService.insertSelective(student);
    }

    @PostMapping(value = "/deleteByPrimaryKey")
    public int deleteByPrimaryKey(@RequestParam(value = "id", required = true) Long id) {
        Student student = Student.builder().id(id).build();
        int row = studentService.deleteByPrimaryKey(student);
        return row;
    }

    @PostMapping(value = "/updateByPrimaryKeySelective")
    public int updateByPrimaryKey(Student student) {
        return studentService.updateByPrimaryKeySelective(student);
    }

    @PostMapping(value = "/selectByPrimaryKey")
    public Student selectByPrimaryKey(Long id) {
        Student student = Student.builder().id(id).build();
        return studentService.selectByPrimaryKey(student);
    }

    @PostMapping(value = "/selectAll")
    public List<Student> selectAll() {
        List<Student> studentList = studentService.selectAll();
        return studentList;
    }
}
